package com.pan.controller;

import com.pan.annotation.TicketCheck;
import com.pan.annotation.enumn.IdentityEnum;
import com.pan.entity.Result;
import com.pan.service.CouponHistoryService;
import com.pan.vo.CouponShowVo;
import com.pan.vo.UserCouponShowVo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

@Controller
public class CouponHistoryController {

    @Resource
    private CouponHistoryService couponHistoryService;

    @ResponseBody
    @GetMapping("/couponHistory/couponInfo/{couponHistoryId}")
    public Result<CouponShowVo> selectCouponInfo(@PathVariable  Long couponHistoryId){
        Result<CouponShowVo> result = couponHistoryService.selectCouponInfo(couponHistoryId);
        return result;
    }


    @ResponseBody
    @GetMapping("/couponHistory/user/{userId}")
    @TicketCheck(ticketName = "userTicket",idName = "userId",identity = IdentityEnum.user)
    public Result<List<UserCouponShowVo>> selectCouponHistoryByUserId(@CookieValue("userTicket") String userTicket,
                                                                      @PathVariable Long userId){

        Result<List<UserCouponShowVo>> result = couponHistoryService.selectByUser(userTicket);
        return result;
    }

//    @ResponseBody
//    @GetMapping("/couponHistory/user/{userTicket}/{userId}")
//    public Result<List<UserCouponShowVo>> selectCouponHistoryByUser(String userTicket,Long us){
//
//        Result<List<UserCouponShowVo>> result = couponHistoryService.selectByUser(userTicket);
//        return result;
//    }

    @ResponseBody
    @GetMapping("/couponHistory/isUserCoupon/{userId}/{couponHistoryId}")
    public Result<Boolean> isUserCoupon(@PathVariable Long userId,
                               @PathVariable Long couponHistoryId){

        Result result = couponHistoryService.isUserCoupon(userId,couponHistoryId);
        return result;
    }


}
